import { Pipe, PipeTransform } from '@angular/core';

interface InitDataItem {
  type: string;
  keys: string[];
}

@Pipe({
  name: 'initdata',
  pure: false
})
// 为临时数据、工作数据附初值,保证各数据最小值为0不为null
export class InitDataPipe implements PipeTransform {

  private initDataItems: InitDataItem[] = [
    {
      type: 'cycle-airport',
      keys: ['checkbag', 'danger', 'guns', 'controlknife', 'goodspackages', 'fakename', 'dangergoods', 'afalarm']
    },
    {
      type: 'cycle-company',
      keys: ['sendperson', 'flightcount', 'flyingtime', 'illegalevent', 'disturbevent', 'helpescort', 'returnperson', 'afalarm']
    },
    {
      type: 'cycle-supervision',
      keys: ['administrationcheck', 'securityaudit', 'securitytest', 'changenotice',
      'changeadvice', 'administrationpublish', 'administrationtalk']
    },
    {
      type: 'cycle-transport',
      keys: ['gcheckcount', 'gguns', 'gbullet', 'gpoliceequipment', 'gboomequipment', 'gcontrolknife', 'gdanger',
      'gdrugs', 'gother', 'gtotal', 'pcheckcount', 'pguns', 'pbullet', 'ppoliceequipment', 'pboomequipment', 'pcontrolknife',
      'pdanger', 'pdrugs', 'pother', 'ptotal', 'hhandlecount', 'hreturn', 'hfakename', 'hfakefile', 'hfakeother', 'htransferother']
    },
    {
      type: 'cycle-passenger',
      keys: ['pcheckcount', 'pfakeidcard', 'ppersonateidcard', 'ptotal', 'pcriminal', 'gcheckcount', 'gguns', 'gbullet', 'gpoliceequipment',
      'gboomequipment', 'gelecequipment', 'gcontrolknife', 'glongknife', 'gdanger', 'gfire', 'glibattery', 'gdrugs', 'gother',
      'gtotal', 'bcheckcount', 'bguns', 'bbullet', 'bpoliceequipment', 'bboomequipment', 'belecequipment', 'bcontrolknife',
      'bdanger', 'bfire', 'blibattery', 'bdrugs', 'bother', 'btotal']
    },
    {
      type: 'cycle-police',
      keys: ['illegalevent', 'disturbevent', 'gchartercount', 'gchartersendperson', 'gflightprotectperson', 'gflightprotectflight',
      'gflightsendperson', 'pcriminalsolvecase', 'pcriminalarrestperson', 'pcriminalescapeperson', 'pterroristsolvecase',
      'pterroristarrestperson', 'pgrouphandle', 'pgroupsendperson', 'pfirecount', 'pfirelose', 'pfirecheck', 'pfirechange',
      'pdrugsolvecase', 'pdrugcount', 'pdrugpersoncount', 'pfaketerroristhandle', 'pfaketerroristsolve', 'pfaketerroristdetain',
      'pfaketerroristpublish', 'ptransportcase', 'ptransportpublish', 'ptransportillegal', 'ptransportaccident', 'afcheckalarm',
      'afflightalarm', 'afcriminalcase', 'afpublish', 'afreject', 'icheckunit', 'icheckimportunit', 'icheckhidedanger',
      'isendnotice', 'iholdteach', 'icrinimal', 'iprotectperson', 'idetain']
    },
    {
      type: 'temp-administration',
      keys: ['administrationcheck', 'hidedanger', 'handnoticebook']
    },
    {
      type: 'temp-air',
      keys: ['sendpolice', 'sendsecurityperson', 'illegalevent', 'disturbevent']
    },
    {
      type: 'temp-floor',
      keys: ['incomeflight', 'outcomeflight', 'incomepassenger', 'outcomepassenger', 'sendsecurityperson', 'checkpassenger',
      'checkbag', 'checkgoods', 'dangergoods', 'guns', 'controlequipment']
    },
    {
      type: 'temp-police',
      keys: ['sendpolice', 'patrolperson', 'checkcar', 'bangoods', 'securitycase', 'criminalcase',
      'criminalperson', 'terroristperson', 'upperson', 'escapeperson', 'cultperson', 'hidedanger']
    }
  ];

  transform(value: any, type: any): any {
    this.initDataItems.map((item: InitDataItem) => {
      if (type === item.type) {
        item.keys.map(key => {
          value[key] = 0;
        });
      }
    });
  }
}
